﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using idea.entity;

namespace pos
{
    public partial class MainFrm : Form
    {
        private Form m_payForm;
        public Form payForm
        {
            get
            {
                return m_payForm;
            }
            set
            {
                m_payForm = value;
            }
        }
        private Form m_quickQuery;
        public Form QuickQueryFrm
        {
            get
            {
                return m_quickQuery;
            }
            set
            {
                m_quickQuery = value;
            }
        }
     
        private Form m_storageForm;
        public Form storageForm
        {
            get
            {
                return m_storageForm;
            }
            set
            {
                m_storageForm = value;
            }
        }
        private Form m_commodityForm;
        public Form commodityForm
        {
            get
            {
                return m_commodityForm;
            }
            set
            {
                m_commodityForm = value;
            }
        }
        private Form m_saleAdminForm;
        public Form saleAdminForm
        {
            get
            {
                return m_saleAdminForm;
            }
            set
            {
                m_saleAdminForm = value;
            }
        }
        public MainFrm()
        {
            InitializeComponent();
            payForm = null;
        }

        private void cmdAdminStroage_Click(object sender, EventArgs e)
        {
          //  this.Hide();
            if (m_storageForm == null)
                m_storageForm = new StorageFrm(this);
           // this.Hide();
            m_storageForm.WindowState = FormWindowState.Maximized;
            m_storageForm.Show();
            

        }
        private void cmdPay_Click(object sender, EventArgs e)
        {
            this.Hide();
            payFrmLogin dlg = new payFrmLogin();
            DialogResult rs = dlg.ShowDialog();
            if (rs == DialogResult.Yes)
            {
                if (consts.groupID == "admin")
                {
                    this.Show();
                    return;
                }
               // m_paytool.userID = dlg.loginID;
              //  this.Text = "当前收银工号  " + m_paytool.userID;
                if (m_payForm == null)
                    m_payForm = new PayFrm(this);
                m_payForm.WindowState = FormWindowState.Maximized;
                m_payForm.Show();
                
            }
            else
            {
                this.Close();
                return;
            }
           
        }
        private void mainForm_Load(object sender, EventArgs e)
        {
            //db_connect.addRef();
            string curDir=Directory.GetCurrentDirectory();
           // string str;
            if (File.Exists(string.Format("{0}\\netverion.txt", curDir)))
            {
                db_connect.g_strCon = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=z:\\pos.mdb";
                this.Text += "--网络版本";
            }
            else
            {
                db_connect.g_strCon = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}\\pos.mdb", curDir);
                this.Text += "--本地版本";
               
                
            }
            
       
        }

        private void button1_Click(object sender, EventArgs e)
        {
            MessageBox.Show(entity_build.build_all());
         
        }

        private void cmdCommodity_Click(object sender, EventArgs e)
        {
            if (m_commodityForm == null)
                m_commodityForm = new CommodityFrm(this);
            
           // this.Hide();
            m_commodityForm.WindowState=FormWindowState.Maximized;
            m_commodityForm.Show();
            
        //    m_commodityForm.Activate();
          //  m_commodityForm.
            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            MessageBox.Show(entity_build.drop_all());
        }

        private void MainFrm_Shown(object sender, EventArgs e)
        {
            string curDir = Directory.GetCurrentDirectory();
          //  string str;
            if (!File.Exists(string.Format("{0}\\netverion.txt", curDir)))
            {
                cmdPay_Click(this, null);
            }
            else
            {
                this.Hide();
                payFrmLogin dlg = new payFrmLogin();
                DialogResult rs = dlg.ShowDialog();
                if (rs == DialogResult.Yes)
                {
                  
                    this.Show();
                }
                else
                {
                    this.Close();
                    return;
                }
            }
        }

        private void cmdSale_Click(object sender, EventArgs e)
        {
            if (consts.groupID != "admin")
                return;
            if (m_saleAdminForm == null)
                m_saleAdminForm = new saleAdminFrm(this);
           // this.Hide();
            m_saleAdminForm.WindowState = FormWindowState.Maximized;
            m_saleAdminForm.Show();
        }

        private void cmdReturn_Click(object sender, EventArgs e)
        {

        }

        private void cmdHStock_Click(object sender, EventArgs e)
        {
            CommodityDealerListFrm dlg=new CommodityDealerListFrm();
            dlg.WindowState = FormWindowState.Maximized;
            dlg.ShowDialog();
        }

        private void MainFrm_FormClosed(object sender, FormClosedEventArgs e)
        {
        //    db_connect.releaseRef();
        }

        private void QuickQuery_Click(object sender, EventArgs e)
        {
            if (m_quickQuery == null)
                m_quickQuery = new QuickQuery(this);
           // this.Hide();
            m_quickQuery.WindowState = FormWindowState.Maximized;
            m_quickQuery.Show();
        }

       
    }
}